<template>
  <section class="main">
    <input
      id="toggle-all"
      class="toggle-all"
      type="checkbox"
      :checked="listyun"
      @change="checkfn"
    />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li
        :class="{ completed: obj.isDone }"
        v-for="(obj, index) in arr"
        :key="obj.id"
      >
        <div class="view">
          <input class="toggle" type="checkbox" v-model="obj.isDone" />
          <label>{{ obj.name }}</label>
          <button
            @click="btn(index)"
            class="destroy"
            v-for="item in arr"
            :key="item"
          ></button>
        </div>
      </li>
    </ul>
  </section>
</template>

<script>
export default {
  props: ["arr"],
  methods: {
    btn(index) {
      this.$emit("shanchu", index);
    },
    checkfn(e) {
      this.arr.forEach((item) => (item.isDone = e.target.checked));
    },
  },
  computed: {
    listyun() {
      return this.arr.every((item) => item.isDone);
    },
  },
};
</script>

<style>
</style>